﻿using System;
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Zavand.Web.Mvc.Manana.FrameworkUnitTests
{
    [TestClass]
    public class BaseModelTest
    {
        [TestMethod]
        public void SetupModelTest()
        {
            var m = new UnitTestModel1();
            var c = new UnitTestController();
            var r = new UnitTestRoute1();

            m.SetupModel(c, r);

            Assert.AreSame(m.GetController(), c);
            Assert.AreSame(m.GetRoute(), r);
        }

        [TestMethod]
        public void GetDefaultLocaleTest()
        {
            var m = new UnitTestModel1();
            Assert.IsTrue(!String.IsNullOrEmpty(m.CallGetDefaultLocale()));
        }

        [TestMethod]
        public void SetLocaleTest()
        {
            var m = new UnitTestModel1();

            var cc = CultureInfo.GetCultures(CultureTypes.AllCultures);

            // Check all standard locales
            foreach (var c in cc)
            {
                if (!String.IsNullOrEmpty(c.Name))
                {
                    m.CallSetLocale(c.Name);
                    Assert.AreEqual(m.Locale, c.Name);
                }
            }

            // Check fake locale
            m.CallSetLocale("sssssss");
            Assert.AreEqual(m.CallGetDefaultLocale(), m.Locale);
        }

        [TestMethod]
        public void GetCultureInfoTest()
        {
            var m = new UnitTestModel1();

            var cc = CultureInfo.GetCultures(CultureTypes.AllCultures);

            // Check all standard locales
            foreach (var c in cc)
            {
                if (String.IsNullOrEmpty(c.Name)) continue;
                m.CallSetLocale(c.Name);
                var ciActual = m.GetCultureInfo();
                var ciExpected = new CultureInfo(m.Locale);
                Assert.AreEqual(ciExpected.LCID, ciActual.LCID);
            }
        }

        [TestMethod]
        public void GetLCIDTest()
        {
            var m = new UnitTestModel1();

            var cc = CultureInfo.GetCultures(CultureTypes.AllCultures);

            // Check all standard locales
            foreach (var c in cc)
            {
                if (String.IsNullOrEmpty(c.Name)) continue;
                m.CallSetLocale(c.Name);
                var ciActual = m.GetCultureInfo();
                var ciExpected = new CultureInfo(m.Locale);
                Assert.AreEqual(ciExpected.LCID, ciActual.LCID);
            }
        }

        [TestMethod]
        public void GetRouteTest()
        {
            var m = new UnitTestModel1();
            var c = new UnitTestController();
            var r = new UnitTestRoute1();

            m.SetupModel(c, r);

            Assert.AreSame(m.GetRoute(), r);
        }

        [TestMethod]
        public void GetControllerTest()
        {
            var m = new UnitTestModel1();
            var c = new UnitTestController();
            var r = new UnitTestRoute1();

            m.SetupModel(c, r);

            Assert.AreSame(m.GetController(), c);
        }
    }
}